import { Message } from 'element-ui'
const instances = []
const newMessage = options => {
  if (options.type === 'blue') {
    let obj = {
      customClass: 'c_customClass_blue',
      iconClass: 'iconfont iconinfo c_iconClass_info'
    }
    options = Object.assign(obj, options)
  }
  if (instances.length <= 2) {
    instances.push(Message(options))
  } else {
    instances[0].close()
    instances.shift()
    instances.push(Message(options))
  }
}
const messageList = ['error', 'success', 'info', 'warning', 'blue']
messageList.forEach(type => {
  newMessage[type] = options => {
    if (typeof options === 'string') {
      options = {
        message: options
      }
    }
    options.type = type
    return newMessage(options)
  }
})
export const message = newMessage